/******************************************************************************
* File description: ResultGuidance.qml
* Function: 实验结果：指导下游方案
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-27
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtGraphicalEffects 1.14
import SvgImage 1.0

Item {
    id: root

    /* property 定义开始 */
    property int headerLeftMargin: 0

    // AL
    property string alR2: "0" // R2
    property string alYIC: "0" // Y轴截距
    property string alEff: "0" // 效率
    property string alK: "0" // 斜率
    property bool alErr: false // 错误

    // AS
    property string asR2: "0" // R2
    property string asYIC: "0" // Y轴截距
    property string asEff: "0" // 效率
    property string asK: "0" // 斜率
    property bool asErr: false // 错误

    // Y
    property string yR2: "0" // R2
    property string yYIC: "0" // Y轴截距
    property string yEff: "0" // 效率
    property string yK: "0" // 斜率
    property bool yErr: false // 错误

    // 过滤按钮文字和选中状态
    property int quanBuCount: 0
    property bool quanBuCheck: true
    property int xuXiShiCount: 0
    property bool xuXiShiCheck: false
    property int ySTRCount: 0
    property bool ySTRCheck: false
    property int miniSTRCount: 0
    property bool miniSTRCheck: false

    // 函数
    // 过滤按钮点击逻辑处理
    function filterBtnClicked(index, isFilter = true){
        quanBuCheck = (index === 0)
        miniSTRCheck = (index === 1)
        ySTRCheck = (index === 2)
        xuXiShiCheck = (index === 3)

        // 过滤数据
        // if(isFilter) root.filterData(index)
    }


    /* property 定义结束 */

    // 容器
    Item {
        id: container
        anchors.fill: parent

        ColumnLayout {
            anchors.fill: parent

            // 头部
            Item {
                id: headerContainer
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                Layout.leftMargin: root.headerLeftMargin

                RowLayout {
                    id: headerRowLayout
                    anchors.fill: parent

                    // 过滤按钮
                    Item {
                        id: checkedBtnContainer
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        Layout.rightMargin: shaixuanCombobox.width

                        RowLayout {
                            anchors {
                                fill: parent
                            }
                            spacing: 20

                            CustomHorSpacerItem {}

                            // 全部
                            CheckableButton {
                                // Layout.preferredWidth: 102
                                // Layout.preferredHeight: 32
                                defaultText: "全部: " + quanBuCount.toString()
                                checkedText: "全部: " + quanBuCount.toString()
                                isChecked: quanBuCheck
                                onClicked: {
                                    filterBtnClicked(0)
                                }
                            }

                            // mini-STR数量
                            CheckableButton {
                                // Layout.preferredWidth: 167
                                // Layout.preferredHeight: 32
                                defaultText: "mini-STR数量: " + miniSTRCount.toString()
                                checkedText: "mini-STR数量: " + miniSTRCount.toString()
                                isChecked: miniSTRCheck
                                onClicked: {
                                    filterBtnClicked(1)
                                }
                            }

                            // Y-STR数量
                            CheckableButton {
                                // Layout.preferredWidth: 143
                                // Layout.preferredHeight: 32
                                defaultText: "Y-STR数量: " + ySTRCount.toString()
                                checkedText: "Y-STR数量: " + ySTRCount.toString()
                                isChecked: ySTRCheck
                                onClicked: {
                                    filterBtnClicked(2)
                                }
                            }

                            // 需稀释样品数量
                            CheckableButton {
                                // Layout.preferredWidth: 172
                                // Layout.preferredHeight: 32
                                defaultText: "需稀释样品数量: " + xuXiShiCount.toString()
                                checkedText: "需稀释样品数量: " + xuXiShiCount.toString()
                                isChecked: xuXiShiCheck
                                onClicked: {
                                    filterBtnClicked(3)
                                }
                            }

                            CustomHorSpacerItem {}

                        }
                    }


                    CustomHorSpacerItem {}

                    // 筛选
                    Item {
                        id: shaixuanCombobox
                        Layout.preferredWidth: 105
                        Layout.fillHeight: true

                        CustomComboBox {
                            anchors.fill: parent
                            comboBgColor: "transparent"
                            comboFontColor: "#FFF"
                            comboBorderColor: "#FFF"
                            comboDefaultText: "筛选"
                            comboFontHorAlign: Text.AlignRight

                            MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    // filterWidgetshow = !filterWidgetshow
                                    shaixuanPopup.opened ? shaixuanPopup.close(): shaixuanPopup.open()
                                }
                            }
                        }

                        // 筛选下拉菜单
                        Popup {
                            id: shaixuanPopup
                            modal: false
                            topPadding: 2
                            padding: 10
                            background: Rectangle {
                                color: "red"
                                visible: false
                            }
                            closePolicy: Popup.NoAutoClose
                            x: -shaixuanPopupContent.width + parent.width - shaixuanPopup.leftPadding
                            y: parent.height
                            clip: true
                            // 打开时动画
                            enter: Transition {
                                NumberAnimation {
                                    property: "height"
                                    from: 0
                                    to: shaixuanPopupContent.height + shaixuanPopup.bottomPadding
                                    duration: 200
                                    easing.type: Easing.InOutQuad
                                }
                            }
                            // 关闭时动画
                            exit: Transition {
                                NumberAnimation {
                                    property: "height"
                                    from: shaixuanPopupContent.height + shaixuanPopup.bottomPadding
                                    to: 0
                                    duration: 200
                                    easing.type: Easing.InOutQuad
                                }
                            }

                            ColumnLayout {
                                anchors.fill: parent

                                FilterWidget {
                                    id: shaixuanPopupContent
                                    Layout.preferredWidth: 588
                                    Layout.preferredHeight: 327
                                }
                            }
                        }
                    }
                }
            }

            // 表格 + 结果数据
            Rectangle {
                id: tableNResultData
                Layout.fillWidth: true
                Layout.fillHeight: true
                border.width: 0
                color: "#C3FFFFFF"
                clip: true
                layer.enabled: true
                layer.effect: OpacityMask {
                    maskSource: Rectangle {
                        width: tableNResultData.width
                        height: tableNResultData.height
                        radius: 12
                    }
                }

                ColumnLayout {
                    anchors.fill: parent

                    // 表格
                    ResultGuidanceTable {
                        id: guidanceTable
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                    }

                    // 结果数据
                    Item {
                        id: resultContainer
                        Layout.fillWidth: true
                        Layout.preferredHeight: resultGridLayout.height
                        Layout.topMargin: 5
                        Layout.bottomMargin: 5
                        Layout.leftMargin: 20
                        Layout.rightMargin: 20

                        GridLayout {
                            id: resultGridLayout
                            width: parent.width
                            height: alCon.height + asCon.height + yCon.height
                            columns: 2
                            columnSpacing: 10
                            rowSpacing: 0

                            // AL
                            Item {
                                id: alCon
                                Layout.fillWidth: true
                                Layout.preferredHeight: alLayout.height

                                ColumnLayout {
                                    id: alLayout
                                    width: parent.width
                                    height: al.height + alErr.height

                                    Label {
                                        id: al
                                        font {
                                            family: 'Alibaba PuHuiTi'
                                            pixelSize: 16
                                        }
                                        color: "#FF1677FF"
                                        text: `AL:R²:${alR2} Y轴截距:${alYIC} 扩散效率:${alEff} 斜率:${alK}`
                                    }

                                    Rectangle {
                                        id: alErrCon
                                        visible: alErr
                                        Layout.fillWidth: true
                                        Layout.preferredHeight: 28
                                        color: "#FFFDF6EC"

                                        // 图片
                                        Item {
                                            id: alErrIcon
                                            width: 16
                                            height: 16
                                            anchors {
                                                left: parent.left
                                                leftMargin: 16
                                                verticalCenter: parent.verticalCenter
                                            }

                                            SvgImage {
                                                anchors.fill: parent
                                                antialiasing: true
                                                source: "qrc:/icons/error.svg"
                                            }
                                        }

                                        // 文字
                                        Label {
                                            id: alErrText
                                            anchors {
                                                left: alErrIcon.right
                                                verticalCenter: parent.verticalCenter
                                            }
                                            font {
                                                family: "Alibaba PuHuiTi"
                                                pixelSize: 16
                                            }
                                            color: "#FF666666"
                                            text: qsTr("错误")
                                            leftPadding: 10
                                        }
                                    }
                                }
                            }

                            // AS
                            Item {
                                id: asCon
                                Layout.fillWidth: true
                                Layout.preferredHeight: asLayout.height

                                ColumnLayout {
                                    id: asLayout
                                    width: parent.width
                                    height: as.height + asErr.height

                                    Label {
                                        id: as
                                        font {
                                            family: 'Alibaba PuHuiTi'
                                            pixelSize: 16
                                        }
                                        color: "#FF67C23A"
                                        text: `AS:R²:${asR2} Y轴截距:${asYIC} 扩散效率:${asEff} 斜率:${asK}`
                                    }

                                    Rectangle {
                                        id: asErrCon
                                        visible: asErr
                                        Layout.fillWidth: true
                                        Layout.preferredHeight: 28
                                        color: "#FFFDF6EC"

                                        // 图片
                                        Item {
                                            id: asErrIcon
                                            width: 16
                                            height: 16
                                            anchors {
                                                left: parent.left
                                                leftMargin: 16
                                                verticalCenter: parent.verticalCenter
                                            }

                                            SvgImage {
                                                anchors.fill: parent
                                                antialiasing: true
                                                source: "qrc:/icons/error.svg"
                                            }
                                        }

                                        // 文字
                                        Label {
                                            id: asErrText
                                            anchors {
                                                left: asErrIcon.right
                                                verticalCenter: parent.verticalCenter
                                            }
                                            font {
                                                family: "Alibaba PuHuiTi"
                                                pixelSize: 16
                                            }
                                            color: "#FF666666"
                                            text: qsTr("错误")
                                            leftPadding: 10
                                        }
                                    }
                                }
                            }

                            // Y
                            Item {
                                id: yCon
                                Layout.fillWidth: true
                                Layout.preferredHeight: yLayout.height

                                ColumnLayout {
                                    id: yLayout
                                    width: parent.width
                                    height: y.height + yErr.height

                                    Label {
                                        id: y
                                        font {
                                            family: 'Alibaba PuHuiTi'
                                            pixelSize: 16
                                        }
                                        color: "#FFEBA23C"
                                        text: `Y:R²:${yR2} Y轴截距:${yYIC} 扩散效率:${yEff} 斜率:${yK}`
                                    }

                                    Rectangle {
                                        id: yErrCon
                                        visible: yErr
                                        Layout.fillWidth: true
                                        Layout.preferredHeight: 28
                                        color: "#FFFDF6EC"

                                        // 图片
                                        Item {
                                            id: yErrIcon
                                            width: 16
                                            height: 16
                                            anchors {
                                                left: parent.left
                                                leftMargin: 16
                                                verticalCenter: parent.verticalCenter
                                            }

                                            SvgImage {
                                                anchors.fill: parent
                                                antialiasing: true
                                                source: "qrc:/icons/error.svg"
                                            }
                                        }

                                        // 文字
                                        Label {
                                            id: yErrText
                                            anchors {
                                                left: yErrIcon.right
                                                verticalCenter: parent.verticalCenter
                                            }
                                            font {
                                                family: "Alibaba PuHuiTi"
                                                pixelSize: 16
                                            }
                                            color: "#FF666666"
                                            text: qsTr("错误")
                                            leftPadding: 10
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
